const { defineConfig } = require("@vue/cli-service");
const webpack = require("webpack");
const { ProvidePlugin } = webpack;
console.log(process.env.NODE_ENV);
// const isPro = process.env.NODE_ENV === "production";
const isDev = process.env.NODE_ENV === "development";
module.exports = defineConfig({
  // devServer: {
  //   proxy: "http://localhost:3000",
  // },
  devServer: {
    hot: true
  },
  // css: {
  //   extract: false,
  //   sourceMap: false,
  //   loaderOptions: {
  //     less: {
  //       lessOptions: {
  //         javascriptEnabled: true
  //       }
  //     }
  //   }
  // },

  productionSourceMap: false,
  publicPath: "./",
  transpileDependencies: true,
  lintOnSave: true,
  configureWebpack: {
    plugins: [
      new ProvidePlugin({
        $: "jquery",
        jQuery: "jquery",
        "window.jQuery": "jquery",
        jquery: "jquery"
      })
    ],
    optimization: {
      splitChunks: {
        chunks: "async",
        minSize: 20000,
        minRemainingSize: 0,
        minChunks: 1,
        maxAsyncRequests: 30,
        maxInitialRequests: 30,
        enforceSizeThreshold: 50000,
        cacheGroups: {
          defaultVendors: {
            test: /[\\/]node_modules[\\/]/,
            priority: -10,
            reuseExistingChunk: true
          },
          default: {
            minChunks: 2,
            priority: -20,
            reuseExistingChunk: true
          }
        }
      }
    }
  },
  chainWebpack: (config) => {
    if (isDev) {
      config.css = {
        extract: false,
        sourceMap: true,
        loaderOptions: {
          less: {
            lessOptions: {
              modifyVars: {
                "@text-color": "#0891B4",
                "@primary-color": "#0891B4",
                "@border-radius-base": "2px",
                "@font-size-base": "16px",
                "@font-size-sm": "16px",
              },
              javascriptEnabled: true
            }
          }
        }
      };
    }
    // if (isPro) {
    //   // 配置包分析器
    //   config.plugin("webpack-bundle-analyzer")
    //     .use(require("webpack-bundle-analyzer").BundleAnalyzerPlugin);
    // }

  }
});
